package com.learning.batterySwapPro.controller;

import com.learning.batterySwapPro.common.response.ApiResponse;
import com.learning.batterySwapPro.common.response.ResultCode;
import com.learning.batterySwapPro.pojo.entity.User;
import com.learning.batterySwapPro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 测试类
 */
@RestController
@RequestMapping("/test")
public class Test {

	@Autowired
	private UserService userService;

	/**
	 * 测试方法
	 */
	@GetMapping("/hello")
	public String hello() {
		return "hello world";
	}

	@GetMapping("/user")
	public ApiResponse<User> user() {
		User user = userService.findById(null);
		if (Objects.isNull(user)) {
			return ApiResponse.fail(ResultCode.NOT_FOUND.getCode(), "用户不存在");

		}

		return ApiResponse.success(user).addMeta("name", "张三").addMeta("age", 18);
	}

}
